package com.cy.pj.sys.controller;

import com.cy.pj.common.pojo.JsonResult;
import com.cy.pj.sys.pojo.SysMenu;
import com.cy.pj.sys.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController //@Controller+@ResponseBody
@RequestMapping("/menu/")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;


    @GetMapping
    public JsonResult doFindMenus(){
        return new JsonResult(sysMenuService.findMenus());
    }


    @GetMapping("treeNodes")
    public JsonResult doFindMenuTreeNodes(){
        return new JsonResult(sysMenuService.findMenuTreeNodes());
    }


    @GetMapping("{id}")
    public JsonResult doFindById(@PathVariable Integer id){
        return new JsonResult(sysMenuService.findById(id));
    }

    @PostMapping
    public JsonResult doSaveMenu(@RequestBody  SysMenu menu){
        sysMenuService.saveMenu(menu);
        return new JsonResult("save ok");
    }

    @PutMapping
    public JsonResult doUpdateMenu(@RequestBody  SysMenu menu){
        sysMenuService.updateMenu(menu);
        return new JsonResult("update ok");
    }
}
